import 'package:app_30/home/vm/tuijian_list_vm.dart';
import 'package:app_30/models/referral_entity.dart';
import 'package:app_30/res/colors.dart';
import 'package:app_30/widgets/my_app_bar.dart';
import 'package:app_30/widgets/my_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';

import 'my_text_field.dart';

class TuijianListPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ViewModelBuilder<TuijianListViewModel>.reactive(
        viewModelBuilder: () => TuijianListViewModel(),
        onModelReady: (viewModel) => viewModel.initialise(),
        builder: (context, viewModel, child) => Scaffold(
            appBar: MyAppBar(
              isBack: true,
              centerTitle: '推荐奖励',
            ),
            body: Column(
              children: [
                Expanded(
                  child: ListView.builder(
                    itemBuilder: (BuildContext context, int index) {
                      ReferralEntity data = viewModel.data[index];
                      return Container(
                        padding: EdgeInsets.all(10),
                        child: Column(
                          children: [
                            buildRow("注册名：", data.user!),
                            buildRow("VIP：", data.vip == "0" ? "否" : "是"),
                            buildRow("注册时间：", data.regtime!),
                            buildRow2("推荐奖励：", '${data.fcje!}元钱'),
                            buildRow("结算状态：", getString(data.tjrjsstatus!)),
                            SizedBox(
                              height: 5,
                            ),
                            SizedBox(
                              width: double.infinity,
                              height: 1,
                              child: Container(
                                color: Colors.grey,
                              ),
                            ),
                          ],
                        ),
                      );
                    },
                    itemCount: viewModel.data.length,
                  ),
                ),
                Column(
                  children: [
                    Row(
                      children: [
                        Text("支付宝账户:",
                            style:
                                TextStyle(fontSize: 15.5, color: Colors.grey)),
                        SizedBox(
                          width: 8,
                        ),
                        Flexible(
                          child: MyTextField(
                            hintText: '请输入',
                            controller: viewModel.zhifubao,
                          ),
                        )
                      ],
                    ),
                    Row(
                      children: [
                        Text("收款人姓名:",
                            style:
                                TextStyle(fontSize: 15.5, color: Colors.grey)),
                        SizedBox(
                          width: 8,
                        ),
                        Flexible(
                          child: MyTextField(
                            hintText: '请输入',
                            controller: viewModel.zhanghao,
                          ),
                        )
                      ],
                    ),
                    Padding(
                      padding: EdgeInsets.only(top: 40, left: 20, right: 20),
                      child: MyButton(
                        key: const Key('tixian'),
                        text: '申 请 结 算',
                        onPressed: viewModel.fcEran,
                      ),
                    )
                  ],
                ),
              ],
            )));
  }

  Container buildRow(title, text) {
    return Container(
      padding: EdgeInsets.only(bottom: 2),
      child: Row(mainAxisSize: MainAxisSize.max, children: [
        SizedBox(
          width: 70,
          child: Text(
            title,
            style: TextStyle(color: Colors.grey, fontSize: 14),
          ),
        ),
        Text(text, style: TextStyle(color: Colors.grey, fontSize: 12))
      ]),
    );
  }

  Container buildRow2(title, text) {
    return Container(
      padding: EdgeInsets.only(bottom: 2),
      child: Row(
        mainAxisSize: MainAxisSize.max,
        children: [
          SizedBox(
            width: 70,
            child: Text(
              title,
              style: TextStyle(color: Colors.grey, fontSize: 14),
            ),
          ),
          Container(
            padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
            decoration: BoxDecoration(
              color: Colours.app_main,
              shape: BoxShape.rectangle,
              borderRadius: BorderRadius.circular(5.0),
            ),
            child: Padding(
              padding: EdgeInsets.all(3),
              child: Row(mainAxisSize: MainAxisSize.min, children: [
                Text(
                  text,
                  textAlign: TextAlign.left,
                  style: TextStyle(fontSize: 12, color: Colors.white),
                )
              ]),
            ),
          ),
        ],
      ),
    );
  }

  String getString(String s) {
    if (s == '1') {
      return '未结算';
    } else if (s == '2') {
      return '结算中';
    } else if (s == '3') {
      return '已结算"';
    } else if (s == '4') {
      return '拒绝结算';
    } else {
      return '免费vip';
    }
  }
}
